# # 1. 求 1 - 100 的和
# sum = 0
# for i in range(1, 101):
#     sum += i
# print(sum)
# # 2. 求 300 - 400 的和
# sum = 0
# for i in range(300, 401):
#     sum += i
# print(sum)
# # 3. 求 1 - 1000 的和
# sum = 0
# for i in range(1, 1001):
#     sum += i
# print(sum)
#用函数进行复用
# def caulate(begin,end):
#     sum=0
#     for i in range(begin,end+1):
#         sum+=i
#     print(sum)
# caulate(1,100)
# #返回值版本
# def caulate(begin,end):
#     sum=0
#     for i in range(begin,end+1):
#         sum+=i
#     return sum
# result =caulate(1,100)
# print(result)

# caulate(1,100)
# caulate(300,400)
# caulate(1,1000)
# def getPoint():
#     x = 10
#     y = 20
#     return x, y
# x, y = getPoint()
# print(x,y)


# x = 20
# def test():
#     global x
#     x = 10
#     print(f'函数内部 x = {x}')
# test()
# print(f'函数外部 x = {x}')
#在 if / while / for 中定义的变量, 在语句外面也可以正常使用
# for i in range(1, 10):
#     print(f'函数内部 i = {i}')
# print(f'函数外部 i = {i}')
# 判定是否是奇数
# def isOdd(num):
#     if num % 2 == 0:
#         return False
#     else:
#         return True
# result = isOdd(10)
# print(result)
# #调用简化为
# print(isOdd(10))


# def a():
#     print("函数 a")
# def b():
#     print("函数 b")
#     a()
# def c():
#     print("函数 c")
#     b()
# def d():
#     print("函数 d")
#     c()
# d()

#计算5的阶乘
# def factor(n):
#     if n == 1:
#         return 1
#     return n * factor(n - 1)
# print("factor(5)=",factor(5))
# def add(x, y, debug=False):
#     if debug:
#         print(f'调试信息: x={x}, y={y}')
#     return x + y
# print(add(10, 20))
# print(add(10, 20, True))